import {getBanners} from '../api/banner'

export default {
  namespaced: true, //开启命名空间
  state:{
    loading:false,
    data:[]
  },
  mutations:{
    setLoading(state,palyod){
      state.loading = palyod;
    },
    setData(state,palyod){
      state.data = palyod;
    },
  },
  actions:{
    async fetchBanner(ctx){
      if(ctx.state.data.length){ // 判断data里面是否有数据存在
        return;
      }
      ctx.commit("setLoading",true);
      const resp = await getBanners();
      ctx.commit("setData",resp);
      ctx.commit("setLoading",false)
    }
  }
}